package com.lq.common.controller;

import com.lq.common.enums.PageNameEnum;
import com.lq.common.service.ShortPageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @author 权哥
 * @version 1.0
 * @date 2023/7/21 23:17
 */
@RestController
public class ScheduledController {

    private static final Logger logger = LoggerFactory.getLogger(Logger.class);

    @Autowired
    private ShortPageService shortPageService;

    /**
     * 获取短文内容
     */
   @Scheduled(cron = "0 0 5 * * ?") // 每天凌晨1点执行任务
//    @Scheduled(fixedRate = 2000)
    @GetMapping("/getShortPage")
    public void getShortPage() throws ParseException, InterruptedException {
        // 在这里编写你的定时任务逻辑
        logger.info("爬虫【语录】定时任务执行中");
        shortPageService.insert(PageNameEnum.hsjz);
        shortPageService.insert(PageNameEnum.zhanan);
        shortPageService.insert(PageNameEnum.tiangou);
    }

   /* @Scheduled(cron = "0 0 8 * * ?")// 每天早八点执行一次*/
    @GetMapping("/sendPage")
    public void sendPage() {
        // 在这里编写你的定时任务逻辑
        logger.info("邮件【语录】定时任务执行中");
        shortPageService.sendPage(PageNameEnum.tiangou.getKeyName());
    }

}
